package lc;

import java.util.Arrays;
import java.util.Scanner;

public class Kuaishou1 {
    
    //数组小和
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       String input = sc.nextLine();
       sc.close();
        String[] ss = input.split("\\s+");
        int[] nums = new int[ss.length];
        for (int i = 0; i < ss.length; i++) {
            nums[i] = Integer.parseInt(ss[i]);
        }
        Kuaishou1 kuaishou1 = new Kuaishou1();
        System.out.println(Arrays.toString(nums));
        System.out.println(kuaishou1.lessSum(nums));
    }
//1 3 4 2 5
    int[] tmp;
    int res;
    public int lessSum(int[] nums) {
        res = 0;
        tmp = new int[nums.length];
        divide(nums, 0, nums.length - 1);
        return res;
    }

    public void divide(int[] nums, int left, int right) {
        if (left >= right) return;
        int mid = (right + left) / 2;
        divide(nums, left, mid);
        divide(nums, mid + 1, right);
        merge(nums, left, mid, right);
    }

    private void merge(int[] nums, int left, int mid, int right) {
        int i = left, j = mid + 1, idx = left;
        
        while (i <= mid && j <= right) {
            if (nums[i] < nums[j]) {
                res += (right - j + 1) * nums[i];
                tmp[idx++] = nums[i++];
            } else {
                // res += (mid - i + 1) * nums[j];
                tmp[idx++] = nums[j++];
            }
        }
        while (i <= left) {
            // res += (right - j + 1) * nums[i];
            tmp[idx++] = nums[i++];
        }
        while (j <= right) {
            tmp[idx++] = nums[j++];
        }
        for (int k = left; k <= right; k++) {
            nums[k] = tmp[k];
        }
    }
}
